package com.group.sliding.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.group.sliding.exception.BadRequestException;
import lombok.Getter;

@Getter
public enum OrderStatus {
    UNPAID(1, "未付款"),
    UNSHIPPED(2, "已付款未发货"),
    NOT_CONFIRMED(3, "已发货未确认"),
    CONFIRMED(4, "已确认交易完成"),
    CANCELED(5, "取消订单");

    @EnumValue
    @JsonValue
    private final int value;
    private final String desc;

    OrderStatus(int value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public static OrderStatus of(int value) {
        switch (value) {
            case 1:
                return UNPAID;
            case 2:
                return UNSHIPPED;
            case 3:
                return NOT_CONFIRMED;
            case 4:
                return CONFIRMED;
            case 5:
                return CANCELED;
            default:
                throw new BadRequestException("订单状态错误");
        }
    }
}
